<?php
/**
 * 更新商品基础数据
 *
 */
$argv[1] = 'dev.fh.taoex.com';
$argv[2] = '2012-11-16 00:00:00';
$argv[3] = '2012-11-16 23:59:59';

$domain = $argv[1];
$sDate = time()-86400;//strtotime($argv[2]);
$eDate = time();//strtotime($argv[3]);


define('COMMAND_MODE', true);

set_time_limit(0);
define('LIB_DIR', dirname(__FILE__) . '/lib/');
require_once(LIB_DIR . 'api/taobao/order.php');
require_once(dirname(__FILE__) . '/lib/init.php');

updateGoods();

function updateGoods() {

	
	
	 
			
 
	
			$db = kernel::database();

			$row = 0;
			$n=0;
			$e=0;
			$handle = fopen("data/product2.csv","r");
			while ($data = fgetcsv($handle, 1000, ",")) {
				$num = count($data);
				//echo "			$num fields in line $row:			\n";
				$row++;
				// 				for ($c=0; $c < $num; $c++) {
				// 					echo $data[$c] . "
				// 					\n";
				// 				}


				$bn=$data[1];
				$barcode=$data[0];
				 
			 

				$sql = "select count(*) as _count from `sdb_ome_goods` where bn='$bn'";
				$r = $db->select($sql);
				$a = intval($r[0]['_count']);
				//echo $a.$sql;
				//continue;
				if($a >0){
					//更新商品价格
					$sql1 = "update `sdb_ome_goods` set barcode='$barcode'   where  bn='$bn'";
					echo "已更新,".$barcode.','.$rs.",".$bn."\n";
					$n++;

					//更新货品库存
					$sql2 = "update `sdb_ome_products` set  barcode='$barcode'   where  bn='$bn'";
					//$sql3 = "update `sdb_ome_branch_product` set  store=$store, safe_store=$safe_store  where  product_id=(select product_id from sdb_ome_products where  bn='$bc')";

					if($db->exec($sql1)){
						$db->exec($sql2);
					}else{
						echo "错误,".$barcode.','.','.$bn."\n";
						$e++;
					}
				}else{
						
					echo "未更新,".$barcode.','.$rs.",".$bn."\n";

				}

				
			}
			fclose($handle);
		 
			
	 
				
	 
			echo "更新".$n."共".$row."错误".$e;
	 
			
}